package ltd.hxya.novel.rabbitmq.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.util.concurrent.FailureCallback;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.util.concurrent.SuccessCallback;

@Slf4j
public class RabbitUtils {
    /**
     * 设置确认回调
     */
    public CorrelationData getCorrelationData(){
        CorrelationData correlationData = new CorrelationData();
        correlationData.getFuture().addCallback(result ->  {
            //执行成功的调用
            if (result.isAck()){
                //确认的处理
                log.debug("rabbitmq调用成功"+result.getReason());
            }else {
                log.error("rabbitmq没有投递到交换机");
            }
        }, ex ->  {
            //执行失败的处理
            log.error("rabbitmq调用失败，异常信息："+ex);
        });

        return correlationData;

    }
}
